#include "stdafx.h"
#include "Scene.h"

#include "Geometry.h"
#include "Blob.h"
#include "Algeb.h"
#include "Material.h"

using namespace rt;

Scene::Scene()
{
	mFieldOfViewRad = PI * 0.25f;
	SetAmbientColor(Color(0.1f, 0.1f, 0.1f, 1.0f));
	mDefaultMaterial = CreateMaterial();

	Spheres = new Sphere[SPHERES_TAB_SIZE];
	SphereMats = new Material*[SPHERES_TAB_SIZE];
	SpheresNum = 0;

	Planes = new Plane[PLANES_TAB_SIZE];
	PlaneMats = new Material*[PLANES_TAB_SIZE];
	PlanesNum = 0;

	Boxes = new Box[BOXES_TAB_SIZE];
	BoxMats = new Material*[BOXES_TAB_SIZE];
	BoxesNum = 0;

	Blobs = new Blob[BLOBS_TAB_SIZE];
	BlobMats = new Material*[BLOBS_TAB_SIZE];
	BlobsNum = 0;

	Algebs = new Algeb[ALGEBS_TAB_SIZE];
	AlgebMats = new Material*[ALGEBS_TAB_SIZE];
	AlgebsNum = 0;

	//for (int i = 0; i < 10 ; i++)
	//{
	//	for (int j = 0; j < 10 ; j++)
	//	{
	//		uint sphIdx = getNextSphereIndex();
	//		Sphere * csph = &Spheres[sphIdx];
	//		csph->SetCenter(XMVectorSet(i*3.0f, 3.0f, j*3.0f + 20.0f, 0.0f));
	//		csph->SetRadiusSquared(1.0f);
	//		SphereMats[sphIdx] = mDefaultMaterial;
	//	}
	//}
}

Scene::~Scene()
{
	delete [] Spheres;
	delete [] Planes;
	delete [] Boxes;
	delete [] Blobs;
	delete [] Algebs;

	delete [] SphereMats;
	delete [] PlaneMats;
	delete [] BoxMats;
	delete [] BlobMats;
	delete [] AlgebMats;

	for (size_t i = 0; i < mLights.size(); i++)
		delete mLights[i];

	for (size_t i = 0; i < mMaterials.size(); i++)
		delete mMaterials[i];
}

Light * Scene::CreateLight()
{
	Light * light = new Light;
	mLights.push_back(light);
	return light;
}

Material * Scene::CreateMaterial()
{
	Material * material = new Material;
	mMaterials.push_back(material);
	return material;
}

